$OpenBSD: patch-imap_src_osdep_unix_Makefile,v 1.5 2017/04/25 09:20:53 ajacoutot Exp $
--- imap/src/osdep/unix/Makefile.orig	Mon Jan 12 06:12:25 2015
+++ imap/src/osdep/unix/Makefile	Thu Mar 10 22:35:28 2016
@@ -44,7 +44,7 @@ IP=4
 # -O3 seems to be safe, but empirical observation from our local expert
 # indicates that in some (many?) cases -O3 code runs slower than -O2.
 
-GCCOPTLEVEL= -O2
+GCCOPTLEVEL=
 
 
 # Try to have some consistency in GCC builds.  We want optimization, but we
@@ -56,9 +56,9 @@ GCC4CFLAGS= $(GCCCFLAGS) -Wno-pointer-sign
 
 # Extended flags needed for SSL.  You may need to modify.
 
-SSLDIR=/usr/local/ssl
-SSLCERTS=$(SSLDIR)/certs
-SSLKEYS=$(SSLCERTS)
+SSLDIR=/usr
+SSLCERTS=/etc/ssl
+SSLKEYS=$(SSLCERTS)/private
 SSLINCLUDE=$(SSLDIR)/include
 SSLLIB=$(SSLDIR)/lib
 
@@ -150,6 +150,8 @@ DEFAULTAUTHENTICATORS=ext md5 pla log
 DEFAULTDRIVERS=imap nntp pop3 mix mx mbx tenex mtx mh mmdf unix news phile
 CHUNKSIZE=65536
 
+.SUFFIXES: .o .so
+
 # Normally no need to change any of these
 
 ARCHIVE=c-client.a
@@ -157,6 +159,7 @@ BINARIES=osdep.o mail.o misc.o newsrc.o smanager.o utf
  dummy.o pseudo.o netmsg.o flstring.o fdstring.o \
  rfc822.o nntp.o smtp.o imap4r1.o pop3.o \
  unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o mix.o
+SOBINARIES=$(BINARIES:.o=.so)
 CFLAGS=-g
 
 CAT=cat
@@ -165,6 +168,11 @@ MV=mv
 RM=rm -rf
 SH=sh
 
+.if ${MACHINE_ARCH} == "sparc64"
+PICFLAG= -fPIC
+.else
+PICFLAG= -fpic
+.endif
 
 # Primary build command
 
@@ -284,6 +292,7 @@ bso:	# OpenBSD
 	 SPOOLDIR=/var \
 	 ACTIVEFILE=/usr/local/news/lib/active \
 	 RSHPATH=/usr/bin/rsh \
+	 LOCKPGM=$(PREFIX)/libexec/mlock \
 	 BASECFLAGS="$(GCCCFLAGS)"
 
 cvx:	# Convex
@@ -864,23 +873,29 @@ vu2:	# VAX Ultrix 2.3, etc.
 
 # Build it!
 
-build:	clean once $(ARCHIVE)
+build: clean once $(ARCHIVE) $(SHLIB)
 
-all:	$(ARCHIVE)
+all:	$(ARCHIVE) $(SHLIB)
 
 $(ARCHIVE): $(BINARIES)
 	sh -c '$(RM) $(ARCHIVE) || true'
 	@$(CAT) ./ARCHIVE
 	@$(SH) ./ARCHIVE
 
+$(SHLIB): $(SOBINARIES)
+	$(CC) -shared $(PICFLAG) -o $(SHLIB) $(SOBINARIES)
+
 .c.o:
 	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` $*.c
 
+.c.so:
+	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` $(PICFLAG) -DPIC $(@:.so=.c) -o $@
 
+
 # Cleanup
 
 clean:
-	sh -c '$(RM) auths.c crexcl.c ip_unix.c linkage.[ch] siglocal.c osdep*.[ch] *.o ARCHIVE *FLAGS *TYPE $(ARCHIVE) || true'
+	sh -c '$(RM) auths.c crexcl.c linkage.[ch] siglocal.c osdep*.[ch] *.o *.so ARCHIVE *FLAGS *TYPE $(ARCHIVE) $(SHLIB) || true'
 
 
 # Dependencies
@@ -915,7 +930,7 @@ utf8aux.o: mail.h misc.h osdep.h utf8.h
 
 # OS-dependent
 
-osdep.o:mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
+OSDEPS=	mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
 	osdep.h env_unix.h tcp_unix.h \
 	osdep.c env_unix.c fs_unix.c ftl_unix.c nl_unix.c tcp_unix.c ip_unix.c\
 	auths.c crexcl.c flockcyg.c flocklnx.c flocksim.c fsync.c \
@@ -929,12 +944,12 @@ osdep.o:mail.h misc.h env.h fs.h ftl.h nl.h tcp.h \
 	write.c sslstdio.c \
 	strerror.c strpbrk.c strstr.c strtok.c strtoul.c \
 	OSCFLAGS
-	@echo Building OS-dependent module
-	@echo If you get No such file error messages for files x509.h, ssl.h,
-	@echo pem.h, buffer.h, bio.h, and crypto.h, that means that OpenSSL
-	@echo is not installed on your system.  Either install OpenSSL first
-	@echo or build with command: make `$(CAT) OSTYPE` SSLTYPE=none
-	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` `$(CAT) OSCFLAGS` -c osdep.c
+
+osdep.o: $(OSDEPS)
+	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` `$(CAT) OSCFLAGS` osdep.c
+
+osdep.so: $(OSDEPS)
+	`$(CAT) CCTYPE` -c `$(CAT) CFLAGS` `$(CAT) OSCFLAGS` $(PICFLAG) -DPIC osdep.c -o $@
 
 osdep.c: osdepbas.c osdepckp.c osdeplog.c osdepssl.c
 	$(CAT) osdepbas.c osdepckp.c osdeplog.c osdepssl.c > osdep.c
